/**
 * command for deleting elements (ItemClass and Items)
  * @author zulianp@lu.unisi.ch & remo.lemma@lu.unisi.ch
 */

package ch.unisi.inf.projects.java.uom.gui.commands;

import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.util.Set;

import javax.swing.KeyStroke;

import ch.unisi.inf.projects.java.uom.elements.*;

public final class ElementDeleteCommand extends Command {
	
	/** We are not going to serialize this class atm */
	private static final long serialVersionUID = -1L;
	
	private final Set<Element> elements;
	
	public ElementDeleteCommand (final Set<Element> elements)
	{
		super();
        putValue(NAME,"Delete Element");
        putValue(SHORT_DESCRIPTION,"Deletes an element");
        putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_D, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
        this.elements = elements;
	}
    
    public void actionPerformed(final ActionEvent ev)
    {  
        for (final Element element : elements) {
        	try {
        		ItemManager.instance().elementDelete(element);
        	}
        	catch (final Exception e) {
        		continue;
        	}
        }
    	fireActionPerformed();
    }
}